////////////////////////////////////////////////////////////////////////////
//
//  Crytek Engine Source File.
//  Copyright (C), Crytek Studios, 2002.
// -------------------------------------------------------------------------
//  File name:   particledialog.h
//  Version:     v1.00
//  Created:     17/6/2003 by Timur.
//  Compilers:   Visual Studio.NET
//  Description: 
// -------------------------------------------------------------------------
//  History:
//
////////////////////////////////////////////////////////////////////////////

#ifndef __particledialog_h__
#define __particledialog_h__
#pragma once

#include "BaseLibraryDialog.h"
#include "Controls\SplitterWndEx.h"
#include "Controls\TreeCtrlEx.h"
#include "Controls\PropertyCtrlEx.h"
#include "Controls\PreviewModelCtrl.h"

class CParticleItem;
class CParticleManager;

/** Dialog which hosts entity prototype library.
*/
class CParticleDialog : public CBaseLibraryDialog
{
	DECLARE_DYNAMIC(CParticleDialog)
public:
	CParticleDialog( CWnd *pParent );
	~CParticleDialog();

	// Called every frame.
	void Update();

	virtual UINT GetDialogMenuID();

protected:
	void DoDataExchange(CDataExchange* pDX);
	BOOL OnInitDialog();
	
	afx_msg void OnAssignParticleToSelection();
	afx_msg void OnResetParticleOnSelection();
	afx_msg void OnGetParticleFromSelection();
	afx_msg void OnEnable() { Enable(false); }
	afx_msg void OnEnableAll() { Enable(true); }
	afx_msg void OnEntityStart();
	afx_msg void OnEntityStop();

	afx_msg void OnDestroy();
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	
	afx_msg void OnAddItem();
	afx_msg void OnPlay();
	afx_msg void OnUpdatePlay( CCmdUI* pCmdUI );
	afx_msg void OnUpdateItemSelected( CCmdUI* pCmdUI );
	afx_msg void OnUpdateObjectSelected( CCmdUI* pCmdUI );
	afx_msg void OnUpdateAssignToSelection( CCmdUI *pCmdUI );
	afx_msg void OnUpdateConvertFromEntity( CCmdUI *pCmdUI );
	afx_msg void OnKeyDown(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnNotifyTreeRClick(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnNotifyTreeLClick(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnPick();
	afx_msg void OnUpdatePick( CCmdUI* pCmdUI );
	afx_msg void OnCopy();
	afx_msg void OnPaste();
	afx_msg void OnSelectAssignedObjects();

	void Enable(bool bAll);

	//////////////////////////////////////////////////////////////////////////
	// Some functions can be overriden to modify standard functionality.
	//////////////////////////////////////////////////////////////////////////
	virtual void InitToolbar( UINT nToolbarResID );
	virtual HTREEITEM InsertItemToTree( CBaseLibraryItem *pItem,HTREEITEM hParent );
	virtual void SelectItem( CBaseLibraryItem *item,bool bForceReload=false );

	//////////////////////////////////////////////////////////////////////////
	CParticleItem* GetSelectedParticle();
	void OnUpdateProperties( IVariable *var );

	bool AssignParticleToEntity( CParticleItem *pItem, CBaseObject *pObject, Vec3 const* pPos = NULL );
	CBaseObject* CreateParticleEntity( CParticleItem *pItem, Vec3 const& pos, CBaseObject* pParent = NULL );

	void UpdateItemState( CParticleItem* pItem, bool bRecursive = false );

	void DropToItem( HTREEITEM hItem, HTREEITEM hSrcItem, CParticleItem *pItem );
	class CEntityObject* GetItemFromEntity();

	DECLARE_MESSAGE_MAP()

	CSplitterWndEx m_wndHSplitter;
	CSplitterWndEx m_wndVSplitter;
	
	CPreviewModelCtrl m_previewCtrl;
	CPropertyCtrlEx m_propsCtrl;
	bool m_bForceReloadPropsCtrl;
	CImageList m_imageList;

	CImageList *m_dragImage;

	bool m_bRealtimePreviewUpdate;

	// Particle manager.
	CParticleManager *m_pPartManager;

	CVarBlockPtr m_vars;
	class CParticleUIDefinition* pParticleUI;

	HTREEITEM m_hDropItem;
	HTREEITEM m_hDraggedItem;

	TSmartPtr<CParticleItem> m_pDraggedItem;
};

#endif // __particledialog_h__
